<template>
    <div class="saveUpdate">
        <el-dialog :close-on-click-modal="false" :title="'添加追分'" :visible.sync="showDialog" @close="$emit('update:showUpdate', false)" :showUpdate="showUpdate" width="500px">
            <el-form :model="DetailInfo" ref="saveChn" label-width="45px" size="mini">
                <dialog-wrapper :MaxWidth="400">
                    <el-form-item prop="remark" label="备注:">
                        <el-input type="textarea" :rows="5" v-model="DetailInfo.remark" placeholder="请输入备注..."></el-input>
                    </el-form-item>
                </dialog-wrapper>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="$emit('update:showUpdate', false)" size="small">取 消</el-button>
                <!-- <el-button v-if="id" type="primary" :loading="loading" @click="updateDetail" size="small">确 定</el-button> -->
                <el-button type="primary" :loading="loading" @click="saveDetail" size="small">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import DialogWrapper from '@/components/DialogWrapper'
import { appendScor} from '@/api'
export default {
    components: { DialogWrapper },
    data() {
      // var checkAmount = (rule, value, callback) => {
      //   if (!value) {
      //     return callback(new Error('充值金额不能为空'));
      //   }
      //   setTimeout(() => {
      //     if (!Number.isInteger(value)) {
      //       callback(new Error('请输入数字值'));
      //     } else {
      //       if (value >= 0) {
      //         callback(new Error('充值金额为负数'));
      //       } else {
      //         callback();
      //       }
      //     }
      //   }, 1000);
      // };
        return {
            setbank: false,
            showDialog: this.showUpdate,
            loading: false,
            DetailInfo: {remark:''},
        //     rules: {
        //   platform: [
        //     { required: true, message: '请选择平台', trigger: 'blur' },
        //   ],
        //   userid: [
        //    { required: true, message: '请输入用户id', trigger: 'blur' },
        //   ],
        //   amount: [
        //     { required: true, message: '请输入充值金额', trigger: 'blur' },
        //     { type: 'number', message: '充值金额必须为数字值'},
        //     { validator: checkAmount, trigger: 'blur' }
        //   ],

        // }
        }
    },
    props: {
        showUpdate: {
            type: Boolean,
            default: false
        },
        id: {
            type: Number
        },
        MerchantsList: { type: Array },
    },
    created() {
        if (this.id) {
            // this.getDetail()
        }
    },
    methods: {
        saveDetail() {
            let self = this
            this.$refs.saveChn.validate(valid => {
                if (valid) {
                    let selectplatform=self.MerchantsList.find(function(value) {
                        return value.id == self.DetailInfo.platform
                    })
                    // debugger
                    let str = "<div style='text-align:left;margin-left:50px;margin-right:50px;'>"
                    // str += "平&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;台:&nbsp;" + selectplatform.name
                    // str += "<p>用&nbsp;户&nbsp;&nbsp;ID:&nbsp;" + self.DetailInfo.userid + "</p>"
                    // str += "<p>充值金额:&nbsp;" + self.DetailInfo.amount + "</p>"
                    str += "<p>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:&nbsp;" + (!self.DetailInfo.remark?'':self.DetailInfo.remark) + "</p></div>"
                    this.$confirm(str, '追分确认', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        center: true,
                        dangerouslyUseHTMLString: true
                    }).then(() => {
                      appendScor(this.id,this.DetailInfo).then(res => {
                      if(res.status === 0){
                        this.$message({ message: '追分成功。',type: 'success' })
                        this.$emit('update:showUpdate', false)
                      }
                    })

                    })

                }
            })
        }
    },
    watch: {
        showUpdate() {
            this.showDialog = this.showUpdate
        }
    }
}
</script>
